﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using CI.Interfaces;

namespace CI.Organism
{
    /// <summary>
    /// SimpleSynapse
    /// </summary>
    [CollectionDataContract(IsReference = true)]
    public class SynapseCollection : List<ISynapse>, ISynapseCollection
    {
        /// <summary>
        /// Find the ISynapse with the specifed guid
        /// </summary>
        /// <param name="guid">guid to find</param>
        /// <returns>ISynapse</returns>
        public ISynapse Find(Guid guid)
        {
            return FindLast(synapse => synapse.Guid == guid);
        }


        /// <summary>
        /// empty ctor needed for xml serializer/deserializer, DO NOT REMOVE
        /// </summary>
        public SynapseCollection() { }

        
        /// <summary>
        /// Dump a list of the synapses
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            string result = null;

            foreach (ISynapse synapse in this)
            {
                result += synapse + Environment.NewLine;
            }

            return result;
        }

    }
}